from rest_framework import serializers

from database.models import *


class UpdateGoodsSerializer(serializers.ModelSerializer):
    uuid = serializers.CharField(label="uuid",
                                 read_only=True)

    name = serializers.CharField(label='商品名称',
                                 required=False,
                                 max_length=100,
                                 min_length=2,
                                 error_messages={
                                     'min_length': '商品名称不少于2位',
                                     'max_length': '商品名称不大于100位',
                                 },
                                 )
    is_top = serializers.BooleanField(label='是否置顶', )

    modifier = serializers.HiddenField(
        default=serializers.CurrentUserDefault())

    class Meta:
        model = Goods
        fields = (
            'uuid',
            'modifier',
            'name',
            'is_top',
        )
